#!/bin/bash

# 测试多用户功能

echo "=========================================="
echo "测试多用户功能"
echo "=========================================="
echo ""

BASE_URL="http://localhost:8080"

# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo "1. 测试user1提交问题..."
response=$(curl -s -X POST "$BASE_URL/api/qa/ask" \
  -H "Content-Type: application/json" \
  -d '{"question":"什么是Java?","userId":2}')
echo "响应: $response"
echo ""

echo "2. 测试admin提交问题..."
response=$(curl -s -X POST "$BASE_URL/api/qa/ask" \
  -H "Content-Type: application/json" \
  -d '{"question":"什么是Spring Boot?","userId":1}')
echo "响应: $response"
echo ""

echo "3. 测试user2提交问题..."
response=$(curl -s -X POST "$BASE_URL/api/qa/ask" \
  -H "Content-Type: application/json" \
  -d '{"question":"什么是MySQL?","userId":3}')
echo "响应: $response"
echo ""

echo "4. 查看所有问答历史..."
response=$(curl -s "$BASE_URL/api/qa/history?page=0&size=10")
echo "响应: $response" | head -c 200
echo "..."
echo ""

echo "5. 只查看user1的问答历史..."
response=$(curl -s "$BASE_URL/api/qa/history?page=0&size=10&userId=2")
echo "响应: $response" | head -c 200
echo "..."
echo ""

echo -e "${GREEN}测试完成！${NC}"
echo ""
echo "请在浏览器中访问 http://localhost:5173 查看前端界面"
echo "你可以在右上角切换用户进行测试"
